package com.xhkj.hk;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.hikvision.artemis.sdk.kafka.data.push.FaceExecute;
import com.hikvision.artemis.sdk.kafka.data.result.ExecuteResult;
import com.hikvision.artemis.sdk.kafka.entity.parse.result.FaceLibData;
import com.hikvision.artemis.sdk.kafka.entity.parse.result.FaceListData;
import com.xhkj.dao.MyFaceLibRecogDataDao;
import com.xhkj.es.UploadFaceData2ES;
import com.xhkj.model.MyFaceLibRecogData;

import lombok.extern.slf4j.Slf4j;

/**
 * 人脸数据业务处理实现
 */

@Slf4j
@Component
public class FaceExecuteHandle extends FaceExecute {
	@Autowired
	private MyFaceLibRecogDataDao dao;
	private static MyFaceLibRecogDataDao mydao;
	@PostConstruct
	public void init(){
		mydao=dao;
	}
	@Override
    public ExecuteResult execute(FaceListData data) {
        try {
        	List<FaceLibData> faceLibRecogList = data.getFaceLibRecogList();
        	MyFaceLibRecogData md = new MyFaceLibRecogData();
        	if(faceLibRecogList.size()>0) {
        		BeanUtils.copyProperties(faceLibRecogList.get(0), md);
        		md.setMyState(0);
        		md.setInsertTime(LocalDateTime.now());
        		mydao.save(md);
        		if(!StringUtils.isEmpty(md.getCertificateNumber())) {
        			UploadFaceData2ES.insert(faceLibRecogList);
        		}
        	}
            return ExecuteResult.success();
        } catch (Exception e) {
            log.error("face data hadle error !",e);
            return ExecuteResult.retry();
        }

    }
}
